package com.example.demo.common.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Builder;
import lombok.Data;
import org.springframework.boot.context.properties.bind.DefaultValue;

/**
 * @author 9523
 * @version V1.0
 * @Project demo
 * @Package com.example.demo.common.entity
 * @Description: 分页参数
 * @Date 2024/9/4 10:07
 */
@Data
public class PageBaseEntity extends BaseEntity{

    //页数
    @TableField(exist = false)
    private Integer pageNum = 1;

    //每页条数
    @TableField(exist = false)
    private Integer pageSize = 10;

    //排序字段
    @TableField(exist = false)
    private String orderField;

    //排序方式
    @TableField(exist = false)
    private String orderRole;


    public String getOrderBy(){
        if(StringUtils.isBlank(orderField)){
            return null;
        }
        if(orderRole==null){
            orderRole="desc";
        }
        return orderField+" "+orderRole;
    }

    public Page getPage(){
        return new Page<>(pageNum,pageSize);
    }

}
